import require from '../utils/require'

export function Login(username: string, password: string) {
  return require.post(
    '/login',
    JSON.stringify({
      username: username,
      password: password
    })
  )
}

export function Register(username: string, password: string, email: string) {
  return require.post(
    '/register',
    JSON.stringify({
      username: username,
      password: password,
      email: email
    })
  )
}

export function checkUsername(username: string, email: string) {
  const params = {
    username: username,
    email: email
  }

  return require.get('/user/checkUsername', params)
}

export function forgetPassword(username: string, password: string) {
  return require.put(
    '/user/forgetPassword',
    JSON.stringify({
      username: username,
      password: password
    })
  )
}

export function queryUserNickname(userId: number) {
  return require.get('/user/queryUserNickname', { userId })
}

export function modifyPassword(userId: number, oldPassword: string, newPassword: string) {
  return require.put(
    '/user/modifyPassword',
    JSON.stringify({
      userId: userId,
      oldPwd: oldPassword,
      newPwd: newPassword
    })
  )
}

export function queryUserProfile(userId: number) {
  return require.get('/user/profile', { userId })
}

export function uploadAvatar(form: any) {
  return require.postAvatar('/user/upload/avatar', form)
}

export function modifyUser(userId: number, nickname: string, avatar: string) {
  return require.put(
    '/user/modify',
    JSON.stringify({
      userId: userId,
      nickname: nickname,
      avatar: avatar
    })
  )
}
